<?php 
namespace Home\Controller;
use Think\Controller;
/**
* 上传图片处理器
*/
class PhotoController extends Controller{
	// 单张图片
	public function addImg($imgs){
		if (IS_POST) {
			set_time_limit (0);
			$user_id = $user_id=session("uid.id");
	        $dir="/Public/Uploads/active/";
	        
	        if(!file_exists($dir))
	        {
	            mkdir($dir,0777,true);
	        }
	        $base64_body = substr(strstr($imgs,','),1);

        	$new_file = "Public/Uploads/active/".$user_id.time().".jpg";

        	$res=file_put_contents($new_file, base64_decode($base64_body));
	    	// $img=__ROOT__."/".$new_file;
	    	$new_file = __ROOT__.'/'.$new_file;

	        return($new_file);

		}
	}

	public function updata($imgs){
		if (IS_POST) {

			set_time_limit (0);
			$user_id=session("uid.id");
	        $dir="/Public/Uploads/active/";
	        if(!file_exists($dir)){
	            mkdir($dir,0777,true);
	        }
	        if ($imgs!=null) {
	            for ($i=0; $i < count($imgs); $i++) {
	              $base64_body = substr(strstr($imgs[$i],','),1);
	              // $new_file[$i]=$dir."f".$i.$user_id.time().".jpg";
	              $new_file[$i] = "Public/Uploads/active/".$i.$user_id.time().".jpg";
	              $a=file_put_contents($new_file[$i], base64_decode($base64_body));
	              // $new_file[$i]=strstr($new_file[$i],'/');
	              $new_file[$i]='/'.$new_file[$i];
	              		// $myfile=fopen("log.txt", "w");fwrite($myfile, $imgs[$i]);
	            }
	        }
	        return($new_file);

		}
	}
}